export const appName = '水务 - ';
export const appDescription = 'water';

export const ENDS_URL = {
  local: {
    label: 'Local',
    value: 'http://127.0.0.1:7001/',
  },

  test: {
    label: 'Test',
    value: 'http://192.168.2.108:8080/',
  },
  dev: {
    label: 'Development',
    value: 'http://www.biggang.top:8070/',
  },

  prod: {
    label: 'Production',
    value: 'http://www.biggang.top:8070/',
  },
};

let _ENDS_URL = '';

export class GlobalOptions {
  constructor() {
    this.setEndsUrl(
      import.meta.env.DEV ? ENDS_URL.dev.value : ENDS_URL.prod.value
    );
  }

  setEndsUrl(url: string) {
    _ENDS_URL = url;
    
    this.updateUrlStash.forEach(callback => {
      callback(url);
    });
  }

  getEndsUrl() {
    return _ENDS_URL;
  }

  updateUrlStash: any[] = [];

  /**
   * 订阅URL变更事件，当URL变更时执行回调函数
   * @param callback URL变更时执行的回调函数
   */
  onUpdateUrl(callback: (url: string) => void) {
    this.updateUrlStash.push(callback);
  }
}

export const globalOptions = new GlobalOptions();
